package o;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Picture;
import android.graphics.RectF;
import android.os.Build.VERSION;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class nu {
    private static final boolean ˊ;
    private static final boolean ˎ;
    private static final boolean ˏ;

    static {
        boolean z;
        boolean z2 = true;
        if (VERSION.SDK_INT >= 19) {
            z = true;
        } else {
            z = false;
        }
        ˎ = z;
        if (VERSION.SDK_INT >= 18) {
            z = true;
        } else {
            z = false;
        }
        ˏ = z;
        if (VERSION.SDK_INT < 28) {
            z2 = false;
        }
        ˊ = z2;
    }

    public static View ˏ(ViewGroup viewGroup, View view, View view2) {
        Matrix matrix = new Matrix();
        matrix.setTranslate((float) (-view2.getScrollX()), (float) (-view2.getScrollY()));
        oi.ˊ(view, matrix);
        oi.ॱ(viewGroup, matrix);
        RectF rectF = new RectF(0.0f, 0.0f, (float) view.getWidth(), (float) view.getHeight());
        matrix.mapRect(rectF);
        int round = Math.round(rectF.left);
        int round2 = Math.round(rectF.top);
        int round3 = Math.round(rectF.right);
        int round4 = Math.round(rectF.bottom);
        View imageView = new ImageView(view.getContext());
        imageView.setScaleType(ScaleType.CENTER_CROP);
        Bitmap ॱ = ॱ(view, matrix, rectF, viewGroup);
        if (ॱ != null) {
            imageView.setImageBitmap(ॱ);
        }
        imageView.measure(MeasureSpec.makeMeasureSpec(round3 - round, 1073741824), MeasureSpec.makeMeasureSpec(round4 - round2, 1073741824));
        imageView.layout(round, round2, round3, round4);
        return imageView;
    }

    private static Bitmap ॱ(View view, Matrix matrix, RectF rectF, ViewGroup viewGroup) {
        boolean isAttachedToWindow;
        Bitmap bitmap = null;
        int i = 0;
        int i2;
        if (ˎ) {
            i2 = !view.isAttachedToWindow() ? 1 : 0;
            isAttachedToWindow = viewGroup == null ? false : viewGroup.isAttachedToWindow();
        } else {
            isAttachedToWindow = false;
            i2 = 0;
        }
        ViewGroup viewGroup2;
        int round;
        int round2;
        float min;
        Canvas canvas;
        Picture picture;
        if (!ˏ || r2 == 0) {
            viewGroup2 = null;
            round = Math.round(rectF.width());
            round2 = Math.round(rectF.height());
            if (round > 0 && round2 > 0) {
                min = Math.min(1.0f, 1048576.0f / ((float) (round * round2)));
                round = Math.round(((float) round) * min);
                round2 = Math.round(((float) round2) * min);
                matrix.postTranslate(-rectF.left, -rectF.top);
                matrix.postScale(min, min);
                if (ˊ) {
                    bitmap = Bitmap.createBitmap(round, round2, Config.ARGB_8888);
                    canvas = new Canvas(bitmap);
                    canvas.concat(matrix);
                    view.draw(canvas);
                } else {
                    picture = new Picture();
                    canvas = picture.beginRecording(round, round2);
                    canvas.concat(matrix);
                    view.draw(canvas);
                    picture.endRecording();
                    bitmap = Bitmap.createBitmap(picture);
                }
            }
            if (ˏ && r2 != 0) {
                viewGroup.getOverlay().remove(view);
                viewGroup2.addView(view, i);
            }
        } else if (isAttachedToWindow) {
            viewGroup2 = (ViewGroup) view.getParent();
            i = viewGroup2.indexOfChild(view);
            viewGroup.getOverlay().add(view);
            round = Math.round(rectF.width());
            round2 = Math.round(rectF.height());
            min = Math.min(1.0f, 1048576.0f / ((float) (round * round2)));
            round = Math.round(((float) round) * min);
            round2 = Math.round(((float) round2) * min);
            matrix.postTranslate(-rectF.left, -rectF.top);
            matrix.postScale(min, min);
            if (ˊ) {
                bitmap = Bitmap.createBitmap(round, round2, Config.ARGB_8888);
                canvas = new Canvas(bitmap);
                canvas.concat(matrix);
                view.draw(canvas);
            } else {
                picture = new Picture();
                canvas = picture.beginRecording(round, round2);
                canvas.concat(matrix);
                view.draw(canvas);
                picture.endRecording();
                bitmap = Bitmap.createBitmap(picture);
            }
            viewGroup.getOverlay().remove(view);
            viewGroup2.addView(view, i);
        }
        return bitmap;
    }

    public static Animator ˋ(Animator animator, Animator animator2) {
        if (animator == null) {
            return animator2;
        }
        if (animator2 == null) {
            return animator;
        }
        Animator animatorSet = new AnimatorSet();
        animatorSet.playTogether(new Animator[]{animator, animator2});
        return animatorSet;
    }
}
